@extends('layouts.forum')

@section('title')
    {{$topic->title or ''}}
@endsection

@section('css')
    <link rel="stylesheet" href="{{cdn('/assets/css/reply-style.css')}}">
@endsection

@section('contaier')
    @include('include.alert', ['type' => 'input'])
    @if (!empty($del))
        <div class="alert alert-danger">
            <strong>通知：</strong>此帖已在回收站
        </div>
    @endif
    <input type="hidden" id="topic_id" value="{{$topic->id or 0}}">
    <input type="hidden" id="cdn" value="{{cdn('')}}">
    <div class="col-md-9 topics-show main-col">
        <div class="panel panel-inverse">
            <div class="panel-heading">
                <div class="panel-title w100">
                    <h2 class="thread-title font m-t-0" style="font-size: 2.0em"><a href="{{url('/forum/plate/'.$topic->pid.'?categorie='.$categorie->id)}}" style="color: {{$categorie->color}}">[{{$categorie->name}}]</a>{{$topic->title or ''}}</h2>
                </div>
                <div class="meta inline-block m-t-10" style="color: #999999">
                    <a href="{{url('/forum/plate/'.$topic->pid)}}" class="remove-padding-left" style="font-size: 1.5em; color: #999">
                        <i class="pe-7s-way text-md" aria-hidden="true"></i>
                        {{$topic->partition()->first()->title or ''}}
                    </a>
                    <a class="author" href="{{url('/user/info/'.$user->id)}}">
                        {{$user->name}}
                    </a>
                    ⋅
                    于 <abbr title="" class="timeago popover-with-html" data-content="{{$topic->created_at}}">{{dateTimeC($topic->created_at)}}前</abbr>
                    ⋅
                    {{$topic->click_count or 0}} 阅读

                </div>
                <div class="clearfix"></div>
            </div>

            <div class="content-body entry-content panel-body ">
                <div class="mce-content-body markdown-body">
                    {{toMakeed_Html($topic->body)}}
                    @if ($topic->chang_user_id > 0)
                        <div class="w100 text-center">
                            <?php $chang_user = \App\models\user\User::find($topic->chang_user_id) ?>
                            本帖由<a href="{{url('/user/info/'.$topic->chang_user_id)}}" target="_blank">{{$chang_user->name or '用户不能被访问'}}</a>于{{$topic->updated_at}}最后编辑
                        </div>
                    @endif
                </div>
                @if (Auth::check() && Auth::user()->userRole->role->flag & \App\other\AdminFlag::ADMIN_FLAG_TOPIC)
                    <div class="w100">
                        <div class="pull-right actions">
                            <a data-ajax="post" id="topic-recomend-button" href="javascript:void(0);" data-url="" class="popover-with-html m-r-10 m-t-5 active" data-content="推荐主题，加精的帖子会出现在首页" data-original-title="" title="">
                                <i class="fa fa-trophy"></i>
                            </a>
                            <a data-ajax="post" id="topic-pin-button" href="javascript:void(0);" data-url="" class="popover-with-html m-r-10 m-t-5" data-content="帖子置顶，会在列表页置顶" data-original-title="" title="">
                                <i class="fa fa-thumb-tack"></i>
                            </a>
                            <a data-ajax="post" id="topic-sink-button" href="javascript:void(0);" data-url="" class="popover-with-html m-r-10 m-t-5" data-content="沉贴，帖子将会被降低排序优先级" data-original-title="" title="">
                                <i class="fa fa-anchor"></i>
                            </a>
                            <a data-method="delete" id="topic-delete-button" href="javascript:void(0);" data-url="" class="popover-with-html m-r-10 m-t-5" data-content="删除" data-original-title="" title="" style="cursor:pointer;">
                                <i class="fa fa-trash-o"></i>

                                <form action="http://php.musicandshop.com/topics/delete/1" method="POST" style="display:none">
                                    <input type="hidden" name="_method" value="delete">
                                    <input type="hidden" name="_token" value="yb13kQAlV5DQ4qcS2FJcOa7qKYiAXMiWKyhBPNd2">
                                </form>
                            </a>
                            <a id="topic-append-button" href="javascript:void(0);" data-toggle="modal"  class="popover-with-html m-r-10 m-t-5"  data-content="帖子附言，添加附言后所有参与讨论的用户都能收到消息提醒，包括点赞和评论的用户" data-original-title="" title="">
                                <i class="fa fa-plus"></i>
                            </a>
                            @if (Auth::id() == $user->id || Auth::user()->userRole->role->flag & \App\other\AdminFlag::ADMIN_FLAG_TOPIC)
                            <a href="{{url('/topic/edit/'.$topic->id)}}" data-content="编辑" class="popover-with-html m-r-10 m-t-5">
                                <i class="fa fa-pencil-square-o"></i>
                            </a>
                            @endif
                        </div>
                        <div class="clearfix"></div>
                    </div>
                @endif
            </div>
        </div>
        <div class="votes-container panel panel-default padding-md">
            <div class="panel-body vote-box text-center">
                <div class="btn-group" style="width: 155px">
                    <button class="btn btn-success m-r-5" id="vote">
                        <i class="fa fa-thumbs-up" aria-hidden="true"></i>
                        点赞
                    </button>
                    <div class="or">or</div>
                    <button class="btn btn-warning m-l-5">
                        <i class="fa fa-heart" aria-hidden="true"></i>
                        打赏
                    </button>
                </div>
                <div class="voted-users">
                    <div class="user-lists">
                        @if (!empty($votes))
                            @foreach($votes as $vote)
                            <a href="{{url('/user/info/'.$vote['uid'])}}" data-userid="{{$vote['uid']}}">
                                <img class="img-thumbnail avatar avatar-middle" src="{{cdn($vote['aratar'])}}" style="width:48px;height:48px;">
                            </a>
                            @endforeach
                        @endif
                    </div>
                    @if (empty($votes))
                        <div class="vote-hint p-20">
                            成为第一个点赞的人吧 <img title=":bowtie:" alt=":bowtie:" class="emoji" src="https://dn-phphub.qbox.me/assets/images/emoji/bowtie.png" align="absmiddle">
                        </div>
                    @endif
                    <a class="voted-template" href="" data-userid="" style="display:none">
                        <img class="img-thumbnail avatar avatar-middle" src="" style="width:48px;height:48px;">
                    </a>
                </div>
            </div>
        </div>
        <!-- Reply List -->
        <div class="replies panel panel-inverse list-panel replies-index">
            <div class="panel-heading">
                <div class="total">回复数量: <b>{{$topic->reply_count or 0}}</b> </div>
            </div>
            <div class="panel-body">
                @if (count($replys) <= 0)
                    <div id="replies-empty-block" class="empty-block">暂无评论~~</div>
                    <div class="pull-right" style="padding-right:20px"></div>
                @else
                    <ul class="list-group row">
                        @foreach($replys as $reply)
                            <?php $user = $reply->user()->first() ?>
                            <li class="list-group-item media border-none" style="margin-top: 0; {{array_key_exists($reply->id, $replyVote) == true ? 'background-color: #fffce9;' : ''}}">
                                <div class="avatar pull-left" style="padding: 0 !important;">
                                    <a href="{{url('/user/info/'.$user->id)}}">
                                        <img class="media-object img-thumbnail avatar" alt="{{$user->name}}" src="{{cdn($user->profile)}}" style="width:48px;height:48px;">
                                    </a>
                                </div>
                                <div class="infos">
                                    <div class="media-heading">
                                        <a href="{{url('/user/info/'.$user->id)}}" title="{{$user->name}}" class="remove-padding-left author">
                                            {{$user->name}}
                                        </a>
                                        @if (!empty($user->userRole()->first()))
                                            <a class="label label-success " style="padding: 2px 10px !important;"
                                               data-content="{{$user->userRole()->first()->role()->first()->display_name}}"
                                               href="{{url('/roles/'.$user->userRole()->first()->role_id)}}"
                                               data-original-title="" title="">{{$user->userRole()->first()->role()->first()->name}}</a>
                                        @endif
                                        <span class="introduction">{{$user->introduction}}</span>
                                        <span class="operate pull-right">
                                            @if (Auth::check() && (\App\other\AdminFlag::ADMIN_FLAG_TOPIC & Auth::user()->userRole->role->flag || Auth::id() === $reply->uid))
                                                <a onclick="deleteReply('{{$reply->id}}', this)"><i class="fa fa-trash m-r-5"></i></a>
                                            @endif
                                            @if (Auth::id() !== $reply->uid)
                                                <a onclick="voteReply('{{$reply->id}}', this)" class=""><i class="fa fa-thumbs-o-up" style="font-size:14px;"></i> <span class="vote-count m-r-5">{{$reply->vote_count}}</span></a>
                                            @endif
                                            <a  href="javascript:void(0)" onclick="replyOne('{{$user->name}}', '{{$user->id}}');" title="回复 {{$user->name}}">
                                                <i class="fa fa-reply"></i>
                                            </a>
                                        </span>

                                        <div class="meta">
                                            <a name="reply{{$reply->index}}" style="color: #999" href="#reply{{$reply->index}}" aria-hidden="true">#{{$reply->index}}</a>
                                            <span> ⋅  </span>
                                            <abbr class="timeago popover-with-html" title="" data-content="{{$reply->created_at}}">{{dateTimeC($reply->created_at)}}前</abbr>
                                        </div>
                                    </div>
                                    <div class="mce-content-body markdown-body">
                                        {{toMakeed_Html($reply->body )}}
                                    </div>
                                </div>
                                <hr class="p-0 m-0">
                            </li>
                        @endforeach
                    </ul>
                @endif
            </div>
        </div>

        <!-- Reply Box -->
        <div class="reply-box form box-block">
            <form method="POST" action="{{url('/topic/reply')}}" accept-charset="UTF-8" id="reply-form">
                {{csrf_field()}}
                <input type="hidden" name="topic_id" value="{{$topic->id or 0}}">
                <div id="reply_notice" class="box">
                    @include('include.topic.tips')
                </div>
                <div class="form-group">
                    <label for="reply_content">回复:</label>
                    <textarea class="form-control" style="max-width: 100%" rows="5" id="reply_content" name="body" cols="50"
                              @if ($del == 'yes' || Auth::check() == false)
                                  disabled
                              @endif
                    ></textarea>
                </div>
                <div class="form-group reply-post-submit">
                    <input type="file" class="hidden" id="uploadImg">
                    <input class="btn btn-primary " id="reply-create-submit" type="submit" value="回复">
                </div>
                <div class="box preview markdown-body" id="preview-box"></div>
            </form>
        </div>
    </div>
    <div class="col-md-3 side-bar">
        <div class="panel panel-default corner-radius">
            <div class="panel-heading text-center">
                <h3 class="panel-title">作者：{{$user->name}}</h3>
            </div>

            <div class="panel-body text-center topic-author-box">
                <a href="{{url('/user/info/'.$user->id)}}">
                    <img src="{{cdn($user->profile)}}" style="width:80px; height:80px;margin:5px;" class="img-thumbnail avatar">
                </a>
                <div class="media-body padding-top-sm">
                    <p class="text-center">{{$user->introduction or ''}}</p>
                    <hr>
                    <div class="topic-author-box text-center col-md-12">
                        @include('include.user.userType')
                    </div>
                </div>
                <span class="text-white">
                    <hr>
                    <a data-method="post" class="btn btn-warning btn-block btn-lg" href="javascript:void(0);"  style="cursor:pointer;">
                        <i class="fa fa-plus"></i> 关注
                    </a>
                </span>
            </div>
        </div>


        <div class="panel panel-default corner-radius">
            <div class="panel-heading text-center">
                <h3 class="panel-title">{{$user->name}} 的其他话题</h3>
            </div>
            <div class="panel-body">
                @if (!empty($topics))
                    <ul class="list">
                    @foreach($topics as $tp)
                        @if ($tp->id != $topic->id)
                        <li>
                            <a href="{{url('/forum/topic/')}}/{{$tp->id or 0}}" class="popover-with-html thread-title" data-content="{{$tp->title or ''}}" data-original-title="" title="">
                                {{$tp->title or ''}}
                            </a>
                        </li>
                        @endif
                    @endforeach
                    </ul>
                @endif
            </div>
        </div>
        <div class="panel panel-default corner-radius">
            <div class="panel-heading text-center">
                <h3 class="panel-title">分类下其他主题</h3>
            </div>
        </div>
    </div>
    <div class="clearfix"></div>
    <div class="banner-container rbs row"></div>

@endsection

@section('js')
    <script src="{{cdn('/assets/js/page/topic.js')}}"></script>
@endsection